<?php

/**
 * Base class for all application tests
 *
 * @category    Ext
 * @package     Ext_Test_PHPUnit
 */
abstract class Ext_Test_PHPUnit_ApplicationTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
    /**
     *
     * @var Zend_Application
     */
    protected $_application;

    /**
     * Resouce names to bootstrap
     *
     * @var array
     */
    protected $_appResources = array();

    /**
     * Default resouces to bootstrap
     *
     * @var array
     */
    protected $_defaultAppResources = array(
        'frontController'
    );

    protected function setUp()
    {
        $this->bootstrap = array($this, 'appBootstrap');

        parent::setUp();
    }
    
    public function appBootstrap()
    {
        $this->_application = new Zend_Application(APPLICATION_ENV,
                APPLICATION_PATH . '/configs/application.ini');

        $bootstrap = $this->_application->getBootstrap();

        foreach ($this->_getAppResources() as $resource) {
            $bootstrap->bootstrap($resource);
        }

        $front = Zend_Controller_Front::getInstance();
        if ($front->getParam('bootstrap') === null) {
            $front->setParam('bootstrap', $this->_application->getBootstrap());
        }
    }

    protected function _getAppResources()
    {
        $resources = array_merge($this->_defaultAppResources, $this->_appResources);
        return $resources;
    }
}
